package zabbix

import (
	"encoding/json"
	"errors"
)

func UsermacroCreateData() (string,map[string]interface{}) {
	method := "usermacro.create"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "hostid": "10198",
        "macro": "{$SNMP_COMMUNITY}",
        "value": "public"
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func UsermacroCreateglobalData() (string,map[string]interface{}) {
	method := "usermacro.createblobal"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "macro": "{$SNMP_COMMUNITY}",
        "value": "public"
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func UsermacroDeleteData() (string,map[string]interface{}) {
	method := "usermacro.delete"
	var data map[string]interface{}
	jsonstr := []byte(`[
        "32",
        "11"
	]`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func UsermacroDeleteglobalData() (string,map[string]interface{}) {
	method := "usermacro.deleteglobal"
	var data map[string]interface{}
	jsonstr := []byte(`[
        "32",
        "11"
	]`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func UsermacroGetData() (string,map[string]interface{}) {
	method := "usermacro.get"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "output": "extend",
        "hostids": "10198"
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func UsermacroUpdateData() (string,map[string]interface{}) {
	method := "usermacro.update"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "hostmacroid": "1",
        "value": "public"
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func UsermacroUpdateglobalData() (string,map[string]interface{}) {
	method := "usermacro.updateglobal"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "globalmacroid": "1",
        "value": "public"
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func UsermacroCreate(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := UsermacroCreateData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}
func UsermacroCreateglobal(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := UsermacroCreateglobalData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func UsermacroDelete(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := UsermacroDeleteData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func UsermacroDeleteglobal(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := UsermacroDeleteglobalData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func UsermacroGet(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := UsermacroGetData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func UsermacroUpdate(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := UsermacroUpdateData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func UsermacroUpdateglobal(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := UsermacroUpdateglobalData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}




